TYP: Add type annotations to Index (pandas/core/indexes/base.py)#64573
TYP: Add type annotations to Index (pandas/core/indexes/base.py)#64573jbrockmendel wants to merge 6 commits intopandas-dev:mainfrom
Conversation
27ca6e9 to
91db6df
Compare
mroeschke
left a comment
There was a problem hiding this comment.
suggestion: For AI to tackle typing, it might be easier to tackle the more "downstream" files first (e.g. groupby, reshaping, etc.) then tackle more upstream functionality (core data structures, internals)
pandas/core/indexes/base.py
Outdated
|
|
||
| @cache_readonly | ||
| def _na_value(self): | ||
| def _na_value(self) -> object: |
There was a problem hiding this comment.
Can we narrow this to Scalar?
There was a problem hiding this comment.
Scalar doesnt include pd.NA, and would also break on 3rd partys (which id be ok not worrying about). I think Hashable is accurate, will update to that
This was AI-written, but in this case I had to go through it line-by-line to convince claude to get things right. Per the OP comment, it was a real slog. Better to do it just once than discard and have to do again down the road. As to the order to do things, I'm pretty sure bottom-up is correct, but will give it a try with some downstream modules and see how it goes. |
|
This needs rebase following #64572. Update: updated |
Add parameter and return type annotations throughout Index, enabling both pyright and mypy type checking for the module. Remove base.py from pyright's exclude list and expand the mypy indexes wildcard to check base individually. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move misplaced type: ignore comments to correct lines in tile.py and base.py, remove stale ignores in resample.py and holiday.py, and add missing mypy ignores in holiday.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add pyright: ignore comments for reportGeneralTypeIssues, reportArgumentType, and reportReturnType in base.py. Restore type: ignore[assignment] for kurtosis alias in frame.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
maybe_unbox_numpy_scalar and cast_scalar_indexer were annotated in GH#64572, making these ignores unnecessary. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57bbcb3 to
1da20df
Compare
|
Trying this on reshape/window downstream modules and finding a) I don't know them nearly as well as indexes.base and b) im not as motivated to do the necessary arm-twisting to get things Just Right. |
This one was a slog getting working.
Summary
Indexinpandas/core/indexes/base.py, enabling both pyright and mypy type checking for the modulebase.pyfrom pyright's exclude list inpyright_reportGeneralTypeIssues.jsonpandas.core.indexes.*mypy wildcard inpyproject.tomlinto individual module entries, excludingbaseso it gets checked__getitem__overloads (SupportsIndex -> Anyvsslice | np.ndarray | list[int] | list[bool] | Series -> Index) to enable precise return types for callersHashablefor label params,Axesfor index-castable params,Frequencyfor freq params)_raise_if_missingand_uniondocstrings to match their actual signaturestype: ignore/pyright: ignorecomments in ~28 other files caused by the newly precise typesTest plan
pandas/core/indexes/base.py(and all spillover files)pandas/core/indexes/base.py🤖 Generated with Claude Code